package p.ithorns.sample.spel;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * SpElAspect
 *
 * @author Ht.L
 * @date 2024-12-26 20:04
 * @since 1.0.0
 */
@Slf4j
@Aspect
@Component
public class SpElAspect {
    /**
     * 拦截加了SpelGetParm注解的方法请求
     *
     * @param param
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Around("@annotation(spElGetParam)")
    public Object beforeInvoke( ProceedingJoinPoint joinPoint, SpElGetParam spElGetParam) throws Throwable {
        Object result = null;
        // 方法名
        String methodName = joinPoint.getSignature().getName();
        //获取动态参数
        String param = SpElUtil.generateKeyBySpEL(spElGetParam.param(), joinPoint);
        log.info("spel获取动态aop参数: {}", param);
        try {
            log.info("执行目标方法: {} ==>>开始......", methodName);
            result = joinPoint.proceed();
            log.info("执行目标方法: {} ==>>结束......", methodName);
            // 返回通知
            log.info("目标方法 " + methodName + " 执行结果 " + result);
        } finally {

        }
        // 后置通知
        log.info("目标方法 " + methodName + " 结束");
        return result;
    }
}